/*
 * 
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','materialResult');

//主要操作controller
authApp.controller("opinionSummaryList",function($scope,$http,$getQueryString,$timeout,$sce){
	
	
	//**********主体方法
	//设置分页初始参数（最好与$scope.currentPage和$scope.itemsPerPage一致！！！！//这边之所以$scope.pageNumber=0是因为后台接口第一页为0）
	$scope.ifFirstTimeQuery=true;
	$scope.pageNumber=0;
	$scope.pageSize=10;
	$scope.pid="";
	$scope.isFirst="";
	try{
		$scope.isFirst=$getQueryString("isFirst");
		var li = document.getElementById("material_manage");   
		li.setAttribute("class", "choosen");
		$scope.pid=$getQueryString("pid");
	}catch(msg){
		
	}
	
	var queryMainApi=apis.queryAuthmaterialResult;
	$scope.queryMain=function(){
		$http({
			method:'post',
			url:queryMainApi,
			data:{},
		}).success(function(response){
			if(response.code=="000000"){
				$scope.queryMainApiCallBack(response);
				//将返回的pagecount和current传到上面的controller
				$scope.$emit('$getPageCountFromApi',response.data);
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("网络出现故障，请确认网络是否连接");
		})
	}
	//捕捉分页点击事件并做处理
	$scope.$on("$pageChanged",function(event,data){
		if(!$scope.ifFirstTimeQuery){//解决第一次会调用两次接口的问题
			$scope.pageNumber=data.currentPage-1;//这边之所以-1是因为后台接口第一页为0
			$scope.queryMain();
		}
		$scope.ifFirstTimeQuery=false;//改变是否是第一次调用接口的状态
	})
	$scope.queryMain();
	
	/*下面为自已编辑部分*/
	
	//调用主接口成功之后的处理方法
	$scope.queryMainApiCallBack=function(response){
		if(response.code=="000000"){
			$scope.schoolId=response.data.schoolId;
			$scope.groupId=response.data.groupId;
			$scope.schoolName=response.data.schoolName;
			$scope.isfollow=response.data.isfollow;
			switch(response.data.major){
			case"0":$scope.major="学前教育";
			break;
			case"1":$scope.major="小学教育";
			break;
			case"2":$scope.major="中学教育";
			break;
			}
			$scope.list=response.data.list;
			angular.forEach($scope.list,function(data,index,array){
				switch(data.state){
				case"0":data.state="未提交";
				break;
				case"1":data.state="未提交";
				break;
				case"2":data.state="已提交";
				break;
				}
			})
			
		}else{
			alert(response.errorMsg);
		}
	}
	
	/*
	 * 
	 * 其它操作方法
	 * 
	 */
	
	
	
	//到指定一级指标查看页面
	$scope.turnToView1level=function(schoolId,itemId,number){
			location.href="material_opinionRecord_view.html?schoolId="+schoolId+"&itemId="+itemId+"&number="+number+"&state=2";
	}
	
	//下载
	$scope.turnToDownLoad=function(schoolId,itemId,number){
		if(window.confirm("是否确定下载 ？")){
			location.href=apis.writeWordFile+"?schoolId="+schoolId+"&itemId="+itemId+"&number="+number;
		}
	}
	
	//下载汇总表
	$scope.download=function(schoolId,groupId){
		if(window.confirm("是否确定下载 ？")){
			location.href=apis.downloadCollect+"?schoolId="+schoolId+"&groupId="+groupId;
		}
	}
	
	//查看汇总表
	$scope.turnToEdit=function(schoolId,state,isfollow){
			location.href="material_opinionSummary_view.html?schoolId="+schoolId+"&state="+state+"&isfollow="+isfollow;
	}
})
